package com.killer.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.killer.db.service.impl.BaseServiceImpl;
import com.killer.goods.entity.Brand;
import com.killer.goods.mapper.BrandMapper;
import com.killer.goods.service.IBrandService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 品牌表 服务实现类
 * </p>
 *
 * @author killer
 * @since 2021-07-30
 */
@Service
public class BrandServiceImpl extends BaseServiceImpl<BrandMapper, Brand> implements IBrandService {

    public LambdaQueryWrapper<Brand> createQueryWrapper(Map<String, Object> searchMap) {
        LambdaQueryWrapper<Brand> queryWrapper = Wrappers.lambdaQuery(Brand.class);
        if (searchMap != null) {
            if (searchMap.get("name") != null) {
                queryWrapper.like(Brand::getName, searchMap.get("name"));
            }
            if (searchMap.get("letter") != null) {
                queryWrapper.like(Brand::getLetter, searchMap.get("letter"));
            }
        }
        return queryWrapper;
    }

    @Override
    public List<Brand> findByCategoryName(String categoryName) {
        return baseMapper.findByCategoryName(categoryName);
    }
}
